<template>
    <div style="width: 500px; margin: auto; margin-top: 150px;">
        <el-form :model="pwdForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="原密码" prop="pwd">
                <el-input v-model="pwdForm.pwd" show-password></el-input>
            </el-form-item>
            <el-form-item label="修改密码" prop="StaffPwd">
                <el-input v-model="pwdForm.StaffPwd" show-password></el-input>
            </el-form-item>
            <el-form-item label="确认密码" prop="againPwd">
                <el-input v-model="pwdForm.againPwd" show-password></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="reset('ruleForm')">修改</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { resetPwdapi } from "@/api/systemSet/resetPwd";
export default {
    data() {
        return {
            pwdForm: {
                id:1,
            },
            rules: {
                pwd: [
                    { required: true, message: '请输入原密码', trigger: 'blur' },
                    { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
                ],
                StaffPwd: [
                    { required: true, message: '请输入新密码', trigger: 'blur' },
                    { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
                ],
                againPwd: [
                    { required: true, message: '请确认密码', trigger: 'blur' },
                    { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        reset(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    
                    if (this.pwdForm.pwd == this.pwdForm.staffPwd) {
                        this.$message({
                            message: '新密码不能与原密码相同',
                            type: 'warning'
                        });
                        return false;
                    }
                    if (this.pwdForm.staffPwd != this.pwdForm.againPwd) {
                        this.$message({
                            message: '两次密码不一致',
                            type: 'warning'
                        });
                        return false;
                    }
                    if(this.pwdForm.pwd!=111111)
                    //sessionStorage.getItem("pwd")
                    {
                        this.$message({
                            message: '原密码不正确',
                            type: 'warning'
                        });
                        return false;
                    }
                    console.log(this.pwdForm);
                    resetPwdapi(this.pwdForm).then(res => {
                        if (res.data.data == true) {
                            this.$message({
                                message: '修改成功',
                                type: 'success'
                            });
                            //跳转到主页面
                            this.$router.push("/");
                        } else {
                            this.$message({
                                message: res.data.message,
                                type: 'warning'
                            });
                        }
                    });

                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        
    },
    created() {
    },
}
</script>
<style></style>